package com.dome.user.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dome.client.entity.vo.out.PageOut;
import com.dome.order.entity.dto.OrderDto;
import com.dome.order.feign.OrderClient;
import com.dome.user.entity.bo.UserEntity;
import com.dome.user.entity.query.UserQuery;
import com.dome.user.entity.vo.UserVO;
import com.dome.user.mapper.UserMapper;
import com.dome.user.service.UserService;
import com.dome.user.transfer.UserTransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,UserEntity> implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Resource
    private OrderClient orderClient;
    @Override
    public UserEntity test(Long id) {

        //OrderDto orderDto = orderClient.selectById(id);
        return userMapper.selectById(id);
    }


    /**
     * 分页
     *
     * @param query
     * @return
     */
    @Override
    public PageOut<List<UserVO>> getList(UserQuery query) {
        Page page=new Page(query.getPageNum(),query.getPageSize());
        List<UserEntity> userEntities=userMapper.getList(page,query);

        List<UserVO> userVOS=UserTransfer.INSTANCE.toUserListVO(userEntities);
        PageOut<List<UserVO>> pageOut=new PageOut<>();
        pageOut.init(page,userVOS);
        return pageOut;
    }

    /**
     * mybatis plus自带分页
     *
     * @param query
     * @return
     */
    @Override
    public Page<List<UserVO>> pagePlus(UserQuery query) {
        Page page=new Page(query.getPageNum(),query.getPageSize());
        EntityWrapper<UserEntity> wrapper=new EntityWrapper<>();
        List<UserEntity> userEntities1 = userMapper.selectPage(page, wrapper);
        page.setRecords(userEntities1);
        return page;
    }
}
